#!/usr/bin/env python 
# -*- coding:utf-8 -*-

"""
if语句的完整形式就是：
if <条件判断1>:
    <执行1>
elif <条件判断2>:
    <执行2>
elif <条件判断3>:
    <执行3>
else:
    <执行4>
"""

# python的 if ,后面跟有一个 :
age = 20
if age > 18:
    print("adult")
elif age < 12:  # elif是else if的缩写
    print("child")
else:
    print("younger")

# input,input()返回的数据类型是str，str不能直接和整数比较
# birth = input('birth: ')
# birth = int(birth)
# if birth < 2000:
#     print('00前')
# else:
#     print('00后')

# bmi calculate
# BMI公式（体重除以身高的平方）
height = 1.75
weight = 80.5
# pow(x,y) :x 的 y 次方
bmi = weight / pow(height, 2)
print(bmi)

# ----------循环------------
# 1.for循环,后面带有':',for...in循环，依次把list或tuple中的每个元素迭代出
names = ['Michael', 'Bob', 'Tracy']
for name in names:
    print(name)

# 产生0-4的整数 0,1,2,3
print(list(range(5)))

sum = 0
numList = list(range(101))

for num in numList:
    sum += num  # sum = sum + num
print(sum)

# 2. while 循环:只要条件满足，就不断循环，条件不满足时退出循环
i = 100
j = 0
while j < i:
    j += 1
print(j)

# practise : 循环依次对list中的每个名字打印出Hello, xxx!
namesList = ['paul', 'harden', 'durant']
msg = "Hello, %s!"
for name in namesList:
    print(msg % name)
    print("Hello,", name)

# break 提前退出循环
i = 100
j = 0
while j < i:
    if j == 50:
        break  # 退出当前while循环
    j += 1
print(j)

# continue :continue的作用是提前结束本轮循环，并直接开始下一轮循环。

